import 'server-only';

import { drizzle } from 'drizzle-orm/node-postgres';
import env from '../env';
import * as authTables from './schema/auth';
import * as commonTables from './schema/common';

export const db = drizzle({
  connection: {
    user: env.POSTGRES_USER,
    host: env.IS_BUILDING ? env.SERVER_IP : env.POSTGRES_HOST,
    port: +env.POSTGRES_PORT,
    password: env.POSTGRES_PASSWORD,
    database: env.POSTGRES_DB,
  },
  schema: {
    ...authTables,
    ...commonTables,
  },
});
